//
//  MBNavigationController.m
//  MobellCloud_ios
//
//  Created by cherry pu on 2017/12/21.
//  Copyright © 2017年 zhangXin. All rights reserved.
//

#import "MBNavigationController.h"
#import "MBTabbarController.h"

@interface MBNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation MBNavigationController

+(void)initialize
{
    UINavigationBar *navBar = [UINavigationBar appearance];
    //设置导航栏颜色
    if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
        [navBar setTranslucent:NO];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.notHiddenBottm = NO;
    
    __weak typeof (self) weakSelf = self;
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = weakSelf;
        self.interactivePopGestureRecognizer.delaysTouchesBegan = NO;
    }
    
    self.navigationBar.layer.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.1].CGColor;
    self.navigationBar.layer.shadowOffset = CGSizeMake(0, 2);
    self.navigationBar.layer.shadowOpacity = 0.7;
    
}


//重写push方法
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //xib时需要判断 self.viewControllers.count > 0
    NSLog(@"%@",self.viewControllers);
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = !self.notHiddenBottm;
    }
    self.notHiddenBottm = NO;
    
    if ([self respondsToSelector:@selector(pushViewController:animated:)]) {
        [super pushViewController:viewController animated:animated];
    }
}

- (BOOL)shouldAutorotate
{
    //禁用自动旋转
    return NO;
}

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if ([self.childViewControllers count] == 1) {
        return NO;
    }
    return YES;
}

// 我们差不多能猜到是因为手势冲突导致的，那我们就先让 ViewController 同时接受多个手势吧。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

@end
